FROM golang:alpine as build-stage
MAINTAINER "thincats@163.com"
WORKDIR /app
# Dependencies for CGO (like sqlite3)
# Comment it if not use mirror
RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/g' /etc/apk/repositories
RUN apk update --no-cache && apk add --no-cache gcc g++

# Install Dependencies
COPY go.mod go.sum ./
ENV GOPROXY=https://goproxy.io
RUN go mod download

COPY . .
# Build main_pretest for test
RUN GOOS=linux GOARCH=amd64 go build -tags netgo -o main cmd/main_pretest.go

FROM alpine:latest as production-stage
WORKDIR /root/
COPY --from=build-stage /app/main /app/db.sqlite ./
EXPOSE 9090
CMD ["./main"]
